import requests
from bs4 import BeautifulSoup
import csv

url = "https://price.21food.cn/market/674.html"

headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
}
resp = requests.get(url,headers = headers)

page = BeautifulSoup(resp.text,'html.parser')
table = page.find("div",attrs = {"class" : "sjs_top_cent_erv"})

tr_list = table.find_all('tr')[1:]

f = open("菜价.csv",mode = "w")
csv_writer = csv.writer(f)

for tr in tr_list:
    tds = tr.find_all('td')
    print(tds[0].text)
    print(tds[2].text)
    print(tds[5].text)
    csv_writer.writerow([tds[0].text,tds[2].text,tds[5].text])

f.close()
resp.close()
# print(table)